package com.zenchn.controller;

import com.zenchn.entity.HttpDataResult;
import com.zenchn.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javafx.util.Pair;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 操作日志记录控制器
 *
 * @author dingxinfa
 * @date 2020-04-20 11:34
 */
@RestController
@RequestMapping(value = "operatinglog")
@Api(value = "操作日志相关接口", tags = "日志查询-操作日志")
@RequiresPermissions("report:log:oper:log")
public class OperatingLogController {
//
//    @Resource
//    private WebPlatformAccessLogRepository webPlatformAccessLogRepository;
//
//
//    /**
//     * 分页模糊查询 操作日志
//     *
//     * @param startTime
//     * @param endTime
//     * @param page
//     * @param pageSize
//     * @param request
//     * @param response
//     * @return
//     */
//    @ApiOperation(value = "操作日志分页列表", notes = "操作日志分页列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(dataType = "String", name = "operAccName", value = "参数名称，搜索关键字操作人"),
//            @ApiImplicitParam(dataType = "String", name = "detail", value = "参数名称，搜索关键字操作详情"),
//            @ApiImplicitParam(dataType = "String", name = "module", value = "参数名称，搜索关键字操作模块"),
//            @ApiImplicitParam(dataType = "Date", name = "startTime", value = "参数名称，开始时间"),
//            @ApiImplicitParam(dataType = "Date", name = "endTime", value = "参数名称，结束时间"),
//            @ApiImplicitParam(dataType = "Integer", name = "page", value = "当前第page页"),
//            @ApiImplicitParam(dataType = "Integer", name = "pageSize", value = "每页pageSize数量")
//    })
//    @GetMapping(value = "/list")
//    public ResponseEntity<HttpDataResult<Map<String, Object>>> findWebPlatformAccessLogList(
//            @RequestParam(required = false, value = "operAccName") String operAccName,
//            @RequestParam(required = false, value = "detail") String detail,
//            @RequestParam(required = false, value = "module") String module,
//            @RequestParam(required = false, value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,
//            @RequestParam(required = false, value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime,
//            @RequestParam(required = false, value = "page", defaultValue = "1") Integer page,
//            @RequestParam(required = false, value = "pageSize", defaultValue = "10") Integer pageSize,
//            HttpServletRequest request, HttpServletResponse response) {
//
//        HttpDataResult<Map<String, Object>> result = new HttpDataResult<>(request.getRequestURI());
//
//        Map<String, Object> dataMap = new HashMap<>(16);
//
//        Pair<Integer, List<WebPlatformAccessLog>> listPair = webPlatformAccessLogRepository.findWebPlatformAccessLogByCondition(
//                operAccName, detail, module, startTime!=null? DateUtils.getOneDayStartTime(startTime):null, endTime!=null? DateUtils.getOneDayEndTime(endTime):null, page, pageSize);
//        dataMap.put("total", listPair.getKey());
//        dataMap.put("list", listPair.getValue());
//
//        result.setData(dataMap);
//        result.setMessage("获取操作日志列表成功");
//        result.setStatus(HttpStatus.OK.value());
//
//        return new ResponseEntity<>(result, HttpStatus.OK);
//    }
//
//    /**
//     * 获取操作日志详情
//     *
//     * @param id
//     * @param request
//     * @param response
//     * @return
//     */
//    @ApiOperation(value = "操作日志详情", notes = "操作日志详情")
//    @ApiImplicitParam(dataType = "String", name = "id", value = "操作日志id")
//    @GetMapping(value = "/detail")
//    public ResponseEntity<HttpDataResult<WebPlatformAccessLog>> getWebPlatformAccessLogDetail(
//            @RequestParam(value = "id") String id,
//            HttpServletRequest request, HttpServletResponse response) {
//        HttpDataResult<WebPlatformAccessLog> result = new HttpDataResult<>(request.getRequestURI());
//
//        WebPlatformAccessLog operatingLogDetail = webPlatformAccessLogRepository.getWebPlatformAccessLogDetail(id);
//        result.setData(operatingLogDetail);
//        result.setMessage("获取操作日志详情成功");
//        result.setStatus(HttpStatus.OK.value());
//
//        return new ResponseEntity<>(result, HttpStatus.OK);
//    }

}
